package com.zr.daoimpl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.zr.dao.SerachUsersByInfoDao;
import com.zr.model.Cuser;

@Repository("serachUsersByInfoDao")
public class SerachUsersByInfoDaoImpl<T> extends BaseDaoImpl<T> implements SerachUsersByInfoDao<T>{

	@Override
	public List<Cuser> getUsersByInfo(int page, int rows, String searType, String sertInfo) {
		List<Cuser> us = new ArrayList<Cuser>();
		String hql = "from Cuser where :searType like :sertInfo";
		Query que = this.getCurrentSession().createQuery(hql);
		que.setString("searType",searType);
		que.setString("sertInfo",'%'+sertInfo+'%');
		que.setFirstResult((page-1)*rows);
		que.setMaxResults(rows);
		
		us = que.list();
		return us;
	}

	@Override
	public int getUsersCountByInfo(String searType, String sertInfo) {
		int i =0;
		List<Cuser> us = new ArrayList<Cuser>();
		String hql = "from Cuser where :searType like :sertInfo";
		Query que = this.getCurrentSession().createQuery(hql);
		que.setString("searType",searType);
		que.setString("sertInfo",'%'+sertInfo+'%');
		us = que.list();
		i = us.size();
		return i;
	}

}
